<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ui>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>无标题文档</title>
		<link rel="stylesheet" type="text/css" charset="utf-8"
			href="/hrms/css/styles.css" />
		<link rel="stylesheet" type="text/css" charset="utf-8"
			href="/hrms/css/flexigrid.css" />
		<link rel="stylesheet" type="text/css" charset="utf-8"
			href="/hrms/css/flexigrid.pack.css" />
		<link rel="stylesheet" type="text/css" charset="utf-8"
			href="/hrms/css/ztree.css" />

		<script type="text/javascript"
			src="/hrms/js/jquery-1.7.2.min.js"></script>

		<script type="text/javascript"
			src="/hrms/js/jquery.container.js"></script>

		<script type="text/javascript"
			src="/hrms/js/common.js"></script>

		<script type="text/javascript"
			src="/hrms/js/flexigrid.pack.js"></script>

		<script type="text/javascript">
		//添加的父级功能树设置
		var a_setting={
				check: {
					enable: true,
					chkStyle: "radio",
					radioType: "all"
				},
				view: {
					dblClickExpand: false
				},
				data: {
					simpleData: {
						enable: true,
						idKey: "annalid",
	                    pIdKey: "parent.annalid",
	                    rootPId: "null",
					},
	            key:{
	                name:"functionname"
	                }
				},
				callback: {
					onClick:a_onClick,
					onCheck: a_onCheck
				}
			};
		function a_showMenu() {
			var funcObj = $("#parentname");
			var funcOffset = $("#parentnam").offset();
			$("#menuContent").slideDown("fast");
 
			$("body").bind("mousedown", onBodyDown);
		}
		
		function a_hideMenu() {
			$("#menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "parent" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
				a_hideMenu();
			}
		}
		function a_onClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			zTree.checkNode(treeNode, !treeNode.checked, null, true);
			return false;
		}
 
		function a_onCheck(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			nodes = zTree.getCheckedNodes(true),
			functionname = "",functionid="";
			
			for (var i=0, l=nodes.length; i<l; i++) {
				functionid += nodes[i].annalid + ",";
				functionname+=nodes[i].functionname+",";
			}
			if (functionname.length > 0 ) functionname = functionname.substring(0, functionname.length-1);
			var form_functionname = $("#parentname");
			form_functionname.attr("value",functionname);
			
			if(functionid.length>0)functionid=functionid.substring(0,functionid.length-1);
			var form_functionid=$("#parentid");
			form_functionid.attr("value",functionid);
		}
		//修改功能菜单
		var u_setting={
				check: {
					enable: true,
					chkStyle: "radio",
					radioType: "all"
				},
				view: {
					dblClickExpand: false
				},
				data: {
					simpleData: {
						enable: true,
						idKey: "annalid",
	                    pIdKey: "parent.annalid",
	                    rootPId: "null",
					},
	            key:{
	                name:"functionname"
	                }
				},
				callback: {
					onClick:u_onClick,
					onCheck: u_onCheck
				}
			};
		function u_showMenu() {
			var funcObj = $("#u_parentname");
			var funcOffset = $("#parentname").offset();
			$("#u_menuContent").slideDown("fast");
 
			$("body").bind("mousedown", u_onBodyDown);
		}
		
		function u_hideMenu() {
			$("#u_menuContent").fadeOut("fast");
			$("body").unbind("mousedown", u_onBodyDown);
		}
		function u_onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "parent" || event.target.id == "u_menuContent" || $(event.target).parents("#u_menuContent").length>0)) {
				u_hideMenu();
			}
		}
		function u_onClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("u_treeDemo");
			zTree.checkNode(treeNode, !treeNode.checked, null, true);
			return false;
		}
 
		function u_onCheck(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("u_treeDemo"),
			nodes = zTree.getCheckedNodes(true),
			functionname = "",functionid="";
			
			for (var i=0, l=nodes.length; i<l; i++) {
				functionid += nodes[i].annalid + ",";
				functionname+=nodes[i].functionname+",";
			}
			if (functionname.length > 0 ) functionname = functionname.substring(0, functionname.length-1);
			var form_functionname = $("#u_parentname");
			form_functionname.attr("value",functionname);
			
			if(functionid.length>0)functionid=functionid.substring(0,functionid.length-1);
			var form_functionid=$("#u_parentid");
			form_functionid.attr("value",functionid);
		}
	$(document).ready( function() {
		$("#fm_add").validationEngine();
		$("#fm_update").validationEngine();
		demand("funcmgr");
		$("#bn_query").click(function(){
			var functioncode=$("#functioncode").val();
			var functionname=$("#functionname").val();
			var extParams={extParam:[{name:"functioncode",value:functioncode},{name:"functionname",value:functionname}]};
			$("#querylist").flexOptions(extParams).flexReload();
		});
		//功能新增
		$("#bn_add").click(function(){
			$("#fm_add").ajaxSubmit({
				success:function(){
					$("#func_add").dialog("close");
					alert("功能新增成功！");
					$("#querylist").flexReload();
				},
				error:function(){
					alert("功能新增失败！");
				}
			});
		});
		
		$("#bn_update").click(function(){
			$("#fm_update").ajaxSubmit({
				success:function(data){
					alert("系统功能详细信息修改成功！");
					$("#func_update").dialog("close");
					$("#querylist").flexReload();
				},
				error:function(){
					alert("系统功能详细信息修改失败！");
				}
			});
		});
		$("#func_update").dialog("close");
		$("#func_add").dialog("close");
	});
</script>

	</head>

	<body onload="loadDemand('funcmgr')">
		<div align="center">
			<br />
			<br />
			<br />
			<table width="80%" border="0" class="table_frame" align="center">

				<thead class="table_title">
					<tr>
						<td align="center">
						功能信息管理
					</td>
					</tr>
				</thead>
				<tr>
					<td>
						<table width="100%" border="0" class="table_block">
							<tr>
								<td align="right">
									功能编号：
								</td>
								<td align="left">
									<input id="functioncode" name="functioncode" type="text" size="20" />
									&nbsp;
								</td>
								<td align="right">
									功能名称：
								</td>
								<td align="left">
									<input id="functionname" name="functionname" type="text" size="20" />
								</td>
							</tr>
							<tr>
								<td colspan="4" align="center">
									<input id="bn_query" name="query" type="button" value="查询" class="button_image" />
									<input name="reset" type="reset" class="button_image" />
								</td>

							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td  height="20"></td>
				</tr>
				<tr>
					<td>
						<div>
							<table id="querylist"></table>
							<script type="text/javascript">
	$("#querylist").flexigrid( {
		url :'/hrms/webservice/resources/function/queryByPage',
		dataType :'json',
		colModel : [ {
			display :'功能编号',
			name :'functioncode',
			width :60,
			sortable :true,
			align :'center'
		}, {
			display :'功能名称',
			name :'functionname',
			width :100,
			sortable :true,
			align :'center'
		}, {
			display :'上级功能名称',
			name :'parent.functionname',
			width :120,
			sortable :true,
			align :'center'
		}, {
			display :'导航路径',
			name :'navpath',
			width :130,
			sortable :true,
			align :'center'
		}, {
			display :'入口服务',
			name :'enterurl',
			width :80,
			sortable :true,
			align :'center'
		},{
			display :'功能状态',
			name :'state',
			width :80,
			sortable :true,
			align :'center',
			hidden:true
		},{
			display :'功能状态',
			name :'stateStr',
			width :80,
			sortable :true,
			align :'center'
		},{
			display :'功能类型',
			name :'typeStr',
			width :80,
			sortable :true,
			align :'center'
		},{
			display:'创建日期',
			name:'createdateStr',
			sortable:true,
			width:120,
			align:'center'
		} ],
		buttons : [ {
			name :'新增功能',
			bclass :'add',
			onpress :add
		}, {
			name :'功能编辑',
			bclass :'edit',
			onpress :update
		}, {
			name :'删除功能',
			bclass :'delete',
			onpress :remove
		}, {
			separator :true
		} ],
		searchitems : [ {
			display :'功能编号',
			name :'functioncode'
		}, {
			display :'功能名称',
			name :'functionname',
			isdefault :true
		} ],
		sortname :"annalid",
		sortorder :"asc",
		usepager :true,
		title :'功能信息列表',
		funcp :true,
		rp :15,
		showTableToggleBtn :true,
		width :1000,
		height :200
	});
	function add(com, grid) {
		//初始化参照
		$.ajax({url:appPath+"webservice/resources/function/queryByRefer",
	               success:function(data){
	                   if(data!=null&&data!="undefined"&&data!=""){
	                       $.fn.zTree.init($("#treeDemo"), a_setting, data);
	                   }
	               }
	    });
		$("#dept_add").dialog("open");
		$.ajax({url:"/hrms/webservice/resources/keyGen/genKey?tablecode=RBAC_FUNCINFO&custom=",
		dataType:"json",
		sucess:function(data){
		},error:function(XMLHttpRequest, textStatus, errorThrown){
		    $("#a_functioncode").attr("value",XMLHttpRequest.responseText);
		}});
		$("#func_add").dialog("open");
	}
	function update(com, grid) {
		//获得选中的记录
		var selected_length=$(".trSelected",grid).length;
		if(selected_length<1){
			alert("请选择一条需要编辑的系统功能后，再点击系统功能编辑按钮！");
			return false;
		}
		if(selected_length>1){
			alert("编辑系统功能只能选择一条记录进行处理，请重新选择！");
			return false;
		}
		//获得机构编号
		var functioncode=$(".trSelected td:nth-child(1) div",grid).text();
		$.ajax({
			url:"/hrms/webservice/resources/function/getFuncDetail?functioncode="+functioncode,
			success:function(_data){
				$("body").DataLink({
					data : _data,
					formId :"fm_update"
				});
			},
			error:function(){
				alert("获取系统功能详细信息时出现异常！");
			}
		});
		//初始化参照
		$.ajax({url:appPath+"webservice/resources/function/queryByRefer",
	               success:function(data){
	                   if(data!=null&&data!="undefined"&&data!=""){
	                       $.fn.zTree.init($("#u_treeDemo"), u_setting, data);
	                   }
	               }
	    });
		$("#func_update").dialog("open");
	}
	function remove(com, grid) {
		//获得选中的记录
		var selected_length=$(".trSelected",grid).length;
		if(selected_length<1){
			alert("请选择一条需要删除的系统功能后，再点击系统功能删除按钮！");
			return false;
		}
		var iscon=confirm('确认要删除选中的系统功能及其下属系统功能吗？');
		if(iscon){
			$(".trSelected td:nth-child(6) div",grid).each(function(index){
				var state=$(this).text();
				if(state==="1"){
					alert("系统功能为正常的系统功能不能被删除，请将权限解除后再行删除！");
					return ;
				}
			});
		var codes="";
		$(".trSelected td:nth-child(1) div",grid).each(function(index){
			if(index)
				codes+=",";
			codes+=$(this).text();
		});
		$.ajax({
			url:"/hrms/webservice/resources/function/delete?functioncodes="+codes,
			success:function(data){
				alert("删除系统功能成功！");
				$("#querylist").flexReload();
			},
			error:function(){
				alert("删除系统功能失败！");
			}
		});
		}
	}
</script>
						</div>
					</td>
				</tr>
			</table>
			<div align="center">
				<br />
				<br />
				<table width="90%" border="0" class="table_frame" align="center">
					<tr>
						<td align="center">
							<input id="demand" name="" type="button" value="需求收集"
								class="button_image" />
						</td>
					</tr>
					<tr>
						<td align="center">
							<div id="demand_input" style="display: none">
								<textarea rows="15" cols="120" id="demand_text"></textarea>
								<br />
								<input id="demand_save" type="button" class="button_image"
									value="保存需求" />
							</div>
						</td>
					</tr>
				</table>
				<table id="demand_des" width="90%" border="0" class="table_frame"
					align="center">
					<thead align="center" class="table_title">
						<tr><td>
							需求描述
						</td></tr>
					</thead>
				</table>
			</div>
		</div>
		<ui:dialog id="func_add" title="功能新增" height="300" width="700"
			modal="true">
			<form id="fm_add"
				action="/hrms/webservice/resources/function/add"
				method="post">
				<table class="table_frame" width="100%">
					<tr>
						<td align="right">
							功能编号:
						</td>
						<td align="left">
							<input type="text"  id="a_functioncode" name="functioncode"
								class="validate[required] text-input" maxlength="128"></input>
							<font color="red">*</font>
						</td>
						<td align="right">
							功能名称:
						</td>
						<td align="left">
							<input type="text" id="functionname" name="functionname"
								class="validate[required] text-input" maxlength="128"></input>
							<font color="red">*</font>
						</td>
					</tr>
					<tr>
						<td align="right">
							父级功能:
						</td>
						<td align="left">
							<input id="parentname" type="text" name="parent.functionname"
								class="validate[required] text-input" maxlength="128"  onclick="a_showMenu();"></input>
								<div id="menuContent" class="menuContent"
								style="display: none; position: absolute;">
								<ul id="treeDemo" class="ztree"
									style="margin-top: 0; width: 180px; height: 100px;"></ul>
								</div>
							<input id="parentid" type="hidden" name="parent.annalidStr"/>
							<font color="red">*</font>
						</td>
						<td align="right">
							导航路径:
						</td>
						<td align="left">
							<input type="text" name="navpath" size=20 />
						</td>
					</tr>
					<tr>
						<td align="right">
							入口服务:
						</td>
						<td align="left">
							<input id="service_add" type="text"  
								size=20  name="enterurl"/>
						</td>
						<td align="right">
							功能类型:
						</td>
						<td align="left">
							<select style="width:160px;" name="type">
								<option value="1">
									路径
								</option>
								<option value="0">
									功能
								</option>
							</select>
						</td>
					</tr>
					<tr>
					<td align="right">
							功能备注:
						</td>
						<td align="left" colspan="3">
							<textarea cols="50" rows="4" id="" name=""></textarea>
						</td>
					</tr>
					<tr>
						<td align="right" colspan="2">
							<input type="button" value="保存" class="button_image" id="bn_add" />
						</td>
						<td align="left" colspan="2">
							<input type="reset" value="重置" class="button_image" />
						</td>
					</tr>
				</table>
			</form>
		</ui:dialog>
		<ui:dialog id="func_update" title="功能信息编辑" height="300" width="700"
			modal=true>
			<form id="fm_update"
				action="/hrms/webservice/resources/function/update"
				method="post">
				<input type="hidden" name="annalidStr"/>
				<input type="hidden" name="createdateStr"/>
				<input type="hidden" name="valid"  />
				<table class="table_frame" width="100%">
					<tr>
						<td align="right">
							功能编号:
						</td>
						<td align="left">
							<input type="text"  id="u_functioncode" name="functioncode"
								class="validate[required] text-input" maxlength="128"></input>
							<font color="red">*</font>
						</td>
						<td align="right">
							功能名称:
						</td>
						<td align="left">
							<input type="text" id="functionname" name="functionname"
								class="validate[required] text-input" maxlength="128"></input>
							<font color="red">*</font>
						</td>
					</tr>
					<tr>
						<td align="right">
							父级功能:
						</td>
						<td align="left">
							<input id="u_parentname" type="text" name="parent.functionname"
								class="validate[required] text-input" maxlength="128"  onclick="u_showMenu();"></input>
								<div id="u_menuContent" class="menuContent"
								style="display: none; position: absolute;">
								<ul id="u_treeDemo" class="ztree"
									style="margin-top: 0; width: 180px; height: 100px;"></ul>
								</div>
							<input id="u_parentid" type="hidden" name="parent.annalidStr"/>
							<font color="red">*</font>
						</td>
						<td align="right">
							导航路径:
						</td>
						<td align="left">
							<input type="text" name="navpath" size=20 />
						</td>
					</tr>
					<tr>
						<td align="right">
							入口服务:
						</td>
						<td align="left">
							<input id="service_add" type="text"  
								size=20  name="enterurl"/>
						</td>
						<td align="right">
							功能类型:
						</td>
						<td align="left">
							<select style="width:160px;" name="type">
								<option value="1">
									路径
								</option>
								<option value="0">
									功能
								</option>
							</select>
						</td>
					</tr>
					<tr>
						<td align="right">
							功能状态:
						</td>
						<td align="left" colspan="3">
							<select style="width:160px;" name="state" disabled="disabled">
								<option value="0">
									新增
								</option>
								<option value="1">
									正常
								</option>
								<option value="2">
									注销
								</option>
							</select>
						</td>
					</tr>
					<tr>
					<td align="right">
							功能备注:
						</td>
						<td align="left" colspan="3">
							<textarea cols="50" rows="4" id="" name=""></textarea>
						</td>
					</tr>
					<tr>
						<td align="right" colspan="2">
							<input type="button" value="保存" class="button_image" id="bn_update" />
						</td>
						<td align="left" colspan="2">
							<input type="reset" value="重置" class="button_image" />
						</td>
					</tr>
				</table>
			</form>
		</ui:dialog>
	</body>
</html>
